#-*- coding:utf-8 -*-
"""
Jeu du pendu - basé sur le dico du projet Moby
Partie graphique du projet utilisant Turtle
Mathieu (et Guillaume, un peu), 2013.
"""

from uturtle import *
from math import pi

t = umonsTurtle()



def croix(t,length):
	length = float(length)
	turnRight(t,45)
	moveForward(t,length/2)
	moveBackward(t,length)
	moveForward(t,length/2)
	turnRight(t)
	moveForward(t,length/2)
	moveBackward(t,length)
	moveForward(t,length/2)
	turnLeft(t, 135)

def jump(t, length):
	dropPen(t)
	moveForward(t, length)
	usePen(t)

def polygon(t, length, n):
	angle = 360.0 / n
	for i in range(n):
		moveForward(t, length)
		turnRight(t, angle)

def circle(t, r):
	nb_cotes = 300
	long = 2*pi*r/nb_cotes
	polygon(t, long, nb_cotes)



def graph_init():
	turnLeft(t, 180)
	jump(t, 240)
	turnLeft(t)
	jump(t, 190)
	turnLeft(t)
	moveForward(t,100)
	moveBackward(t,50)
	turnLeft(t)
	moveForward(t,350)
	turnRight (t)
	moveForward (t,250)
	turnRight(t)
	moveForward(t,50)
	turnLeft(t)

def graph_draw(step):
	r_tete = 25
	l_cou = 10
	a_bras = 30
	l_bras = 50
	l_corps = 60
	a_jambes = 15
	l_jambes = 65
	c_feu = 50
	d_feu = 100
	
	if step==1:
		#tête
		circle(t, r_tete)
		turnRight(t)
		jump(t, r_tete*2)
	elif step==2:
		#cou
		moveForward(t, l_cou)
	elif step==3:
		#bras à notre gauche
		turnRight(t, a_bras)
		moveForward(t, l_bras)
		moveBackward(t, l_bras)
		turnLeft(t, a_bras*2)
	elif step==4:
		#bras à notre droite
		moveForward(t, l_bras)
		moveBackward(t, l_bras)
		turnRight(t, a_bras)
	elif step==5:
		#corps
		moveForward(t, l_corps)
	elif step==6:
		#jambe à notre gauche
		turnRight(t, a_jambes)
		moveForward(t, l_jambes)
		moveBackward(t, l_jambes)
		turnLeft(t, a_jambes*2)
	elif step==7:
		#jambe à notre droite
		moveForward(t, l_jambes)
		moveBackward(t, l_jambes)
		turnRight(t, a_jambes)
	elif step==8:
		#feu (schématisé, hein)
		jump(t, d_feu)
		turnLeft(t, 30)
		polygon(t, c_feu, 3)
		turnRight(t, 210)
	elif step==9:
		#yeux barrés (les deux)
		d = d_feu + l_corps + l_cou + float(r_tete)*4/3
		jump(t, d)
		turnLeft(t)
		jump(t,10)
		croix(t,5)
		turnLeft(t, 180)
		jump(t,2*10)
		croix(t,5)



if __name__ == '__main__':
	graph_init()
	#turnRight(t)
	for i in range(0, 10):
		graph_draw(i)
	wait()
